import sys
from PyQt6.QtWidgets import QApplication
from ui.login_window import LoginWindow
from ui.user_window import UserWindow
from ui.admin_window import AdminWindow

def main():
    app = QApplication(sys.argv)

    login_win = LoginWindow()
    login_win.show()

    # 登录成功后打开不同窗口
    def on_login_success(username, is_admin):
        login_win.hide()
        if is_admin:
            admin_win = AdminWindow(main_window=login_win)# 传入主窗口，便于返回
            admin_win.show()
            # 防止窗口被GC
            app.admin_win = admin_win
        else:
            user_win = UserWindow(username,main_window=login_win)
            user_win.show()
            app.user_win = user_win

    login_win.login_success.connect(on_login_success)

    sys.exit(app.exec())

if __name__ == "__main__":
    main()
